﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Fc.报表
{
    public class JieGuJinDuData
    {
        public double[] Data = new double[450];

        public void QueryData(int fenchang, int chanpin, DateTime d1, DateTime d2, DateTime d3)
        {

            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "接箍生产日报数据";
            Cmd.CommandType = CommandType.StoredProcedure;


            Cmd.Parameters.Add(new SqlParameter("@分厂ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, fenchang));
            Cmd.Parameters.Add(new SqlParameter("@产品类别ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, chanpin));
            Cmd.Parameters.Add(new SqlParameter("@d1", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d1));
            Cmd.Parameters.Add(new SqlParameter("@d2", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d2));
            Cmd.Parameters.Add(new SqlParameter("@d3", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d3));

            SqlDataReader Reader = Cmd.ExecuteReader();
            int x = 0;
            int gongduan;
            while (Reader.Read())
            {
                if (Reader.IsDBNull(2)) continue;
                if ((int)Reader["类别"] == 0)
                {
                    x = 0;
                }
                else if ((int)Reader["类别"] == 1)
                {
                    x = 200;
                }
                else
                {
                    x = 400;
                }
                gongduan = (int)Reader["工段"];
                if (gongduan > 0 && gongduan <= 4)
                {
                    x += (gongduan - 1) * 50;
                }

                Data[x + 0] = (int)Reader["原料投入根数"];
                Data[x + 1] = Convert.ToDouble((decimal)Reader["原料投入重量"]);
                Data[x + 2] = (int)Reader["切料支数"];
                Data[x + 3] = (int)Reader["粗车合格"];
                Data[x + 4] = (int)Reader["粗车不合格"];
                Data[x + 5] = (int)Reader["打字"];
                Data[x + 6] = (int)Reader["磁粉碳伤合格"];
                Data[x + 7] = (int)Reader["磁粉碳伤不合格"];
                Data[x + 8] = (int)Reader["磷化支数"];
                Data[x + 9] = Convert.ToDouble((decimal)Reader["边角料量"]);

                Data[x + 10] = (int)Reader["车丝1"];
                Data[x + 11] = (int)Reader["车丝2"];
                Data[x + 12] = (int)Reader["车丝3"];
                Data[x + 13] = (int)Reader["车丝4"];
                Data[x + 14] = (int)Reader["车丝5"];
                Data[x + 15] = (int)Reader["车丝6"];
                Data[x + 16] = (int)Reader["车丝7"];
                Data[x + 17] = (int)Reader["车丝8"];
                Data[x + 18] = (int)Reader["车丝9"];
                Data[x + 19] = (int)Reader["车丝10"];

                Data[x + 20] = (int)Reader["车丝11"];
                Data[x + 21] = (int)Reader["车丝12"];
                Data[x + 22] = (int)Reader["车丝13"];
                Data[x + 23] = (int)Reader["车丝14"];
                Data[x + 24] = (int)Reader["车丝15"];
                Data[x + 25] = (int)Reader["车丝16"];
                Data[x + 26] = (int)Reader["车丝17"];
                Data[x + 27] = (int)Reader["车丝18"];
                Data[x + 28] = (int)Reader["车丝19"];
                Data[x + 29] = (int)Reader["车丝20"];

                Data[x + 30] = (int)Reader["车废1"];
                Data[x + 31] = (int)Reader["车废2"];
                Data[x + 32] = (int)Reader["车废3"];
                Data[x + 33] = (int)Reader["车废4"];
                Data[x + 34] = (int)Reader["车废5"];
                Data[x + 35] = (int)Reader["车废6"];
                Data[x + 36] = (int)Reader["车废7"];
                Data[x + 37] = (int)Reader["车废8"];
                Data[x + 38] = (int)Reader["车废9"];
                Data[x + 39] = (int)Reader["车废10"];

                Data[x + 40] = (int)Reader["车废11"];
                Data[x + 41] = (int)Reader["车废12"];
                Data[x + 42] = (int)Reader["车废13"];
                Data[x + 43] = (int)Reader["车废14"];
                Data[x + 44] = (int)Reader["车废15"];
                Data[x + 45] = (int)Reader["车废16"];
                Data[x + 46] = (int)Reader["车废17"];
                Data[x + 47] = (int)Reader["车废18"];
                Data[x + 48] = (int)Reader["车废19"];
                Data[x + 49] = (int)Reader["车废20"];

            }
            Reader.Close();
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Close();
            Conn.Dispose();
        }
    }
}
